package com.jcl.recruit.console.report.service;

import com.jcl.core.utils.CollectionUtils;
import com.jcl.core.utils.DateUtils;
import com.jcl.core.utils.StringUtils;
import com.jcl.recruit.console.report.logic.ConsoleReportLogic;
import com.jcl.recruit.elasticsearch.resume.vo.ElasticReportCondition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @ClassName ConsoleReportService
 * @Author yyliu
 * @Date 2018/12/25 15:57
 * @Version 1.0
 **/
@Service
public class ConsoleReportService {

    @Autowired
    private ConsoleReportLogic consoleReportLogic;

    public List<Map<String, Object>> pieChar(ElasticReportCondition condition) {
        condition = defaultDay(condition);
        List<Map<String, Object>> resultList = consoleReportLogic.pieChar(condition);
        return resultList;
    }

    public Map<String, Object> barGraph(ElasticReportCondition condition) {
        condition = defaultDay(condition);
        Map<String, Object> dataMap = consoleReportLogic.barGraph(condition);
        return dataMap;
    }

    public ElasticReportCondition defaultDay(ElasticReportCondition condition){
        if(StringUtils.isEmpty(condition.getCorpCode())){
            condition.setCorpCode(null);
        }
        if(null == condition.getStartDate()){
            Date endDate = new Date();
            Date startDate = DateUtils.addDays(endDate, -7);
            condition.setStartDate(DateUtils.format(startDate));
        }
        if(null == condition.getEndDate()){
            condition.setEndDate(DateUtils.format(new Date()));
        }

        return condition;
    }
}
